package com.inputabc.ct.v1.ui.inputbox.component;

import com.inputabc.EzGUIFramework.util.alias.Ez;
import com.inputabc.ct.v1.context.Components;
import com.inputabc.ct.v1.context.ComponentsBuilder;
import com.inputabc.ct.v1.ui.TextBox;

import javax.swing.*;
import java.awt.*;

public class InputBoxFrame extends JFrame {
    private InputBoxMainPanel inputBoxMainPanel;
    private Components textBoxComponents = ComponentsBuilder.getComponentsContext().get(TextBox.class);
    private JFrame textBoxFrame = (JFrame) textBoxComponents.get("textBoxFrame");
    
    {
        inputBoxMainPanel = new InputBoxMainPanel();
        setName(getClass().getName());
    }

    public InputBoxFrame() {
        // 设置内容面板
        setContentPane(inputBoxMainPanel);
        
        // 设置窗口属性
        setUndecorated(true);
        Ez.removeButtonDottedLine(this);
        setAlwaysOnTop(true);
        
        // 设置尺寸约束
        setMaximizedBounds(textBoxFrame.getMaximizedBounds());
        setMinimumSize(textBoxFrame.getMinimumSize());
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // 设置窗口背景透明，以支持圆角效果
        setBackground(new Color(0, 0, 0, 0));
    }

    /**
     * 重写paint方法，添加阴影效果
     */
    @Override
    public void paint(Graphics g) {
        // 启用抗锯齿
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        
        // 绘制阴影
        int shadowGap = 5;
        int shadowOffset = 4;
        int shadowAlpha = 60;
        Color shadowColor = new Color(0, 0, 0, shadowAlpha);
        
        g2d.setColor(shadowColor);
        
        // 绘制外层阴影
        g2d.fillRoundRect(
                shadowOffset, 
                shadowOffset, 
                getWidth() - shadowOffset - shadowGap, 
                getHeight() - shadowOffset - shadowGap, 
                15, 15);
                
        g2d.dispose();
        
        // 调用父类方法绘制其余部分
        super.paint(g);
    }

    public InputBoxMainPanel getInputBoxMainPanel() {
        return inputBoxMainPanel;
    }

    public void setInputBoxMainPanel(InputBoxMainPanel inputBoxMainPanel) {
        this.inputBoxMainPanel = inputBoxMainPanel;
    }
}
